function Zhu2022GAD_XDay_RM(XDay_RM_Summary)
%% get cross-day RM vs deltaT for p-WTs

% G18
T1(:,1) = (extractfield(XDay_RM_Summary.G2_F4_18, 'Date1'))';
T1(:,2) = (extractfield(XDay_RM_Summary.G2_F4_18, 'Date2'))';
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

for n = 1:size(T1,1)
    deltaT1(n,1) = daysact(T1(n,1),T1(n,2));
end

RM1 (:,1) = extractfield(XDay_RM_Summary.G2_F4_18, 'Memory_Index');

% G28
T2(:,1) = (extractfield(XDay_RM_Summary.G2_F52_28, 'Date1'))';
T2(:,2) = (extractfield(XDay_RM_Summary.G2_F52_28, 'Date2'))';
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

for n = 1:size(T2,1)
    deltaT2(n,1) = daysact(T2(n,1),T2(n,2));
end

RM2 (:,1) = extractfield(XDay_RM_Summary.G2_F52_28, 'Memory_Index');

% G31
T3(:,1) = (extractfield(XDay_RM_Summary.G2_F52_31, 'Date1'))';
T3(:,2) = (extractfield(XDay_RM_Summary.G2_F52_31, 'Date2'))';
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

for n = 1:size(T3,1)
    deltaT3(n,1) = daysact(T3(n,1),T3(n,2));
end

RM3 (:,1) = extractfield(XDay_RM_Summary.G2_F52_31, 'Memory_Index');

% G34
T4(:,1) = (extractfield(XDay_RM_Summary.G2_F52_34, 'Date1'))';
T4(:,2) = (extractfield(XDay_RM_Summary.G2_F52_34, 'Date2'))';
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

for n = 1:size(T4,1)
    deltaT4(n,1) = daysact(T4(n,1),T4(n,2));
end

RM4 (:,1) = extractfield(XDay_RM_Summary.G2_F52_34, 'Memory_Index');

% G42
T5(:,1) = (extractfield(XDay_RM_Summary.G2_F62_42, 'Date1'))';
T5(:,2) = (extractfield(XDay_RM_Summary.G2_F62_42, 'Date2'))';
T5 = datetime(T5,'InputFormat','yyyy-MM-dd');

for n = 1:size(T5,1)
    deltaT5(n,1) = daysact(T5(n,1),T5(n,2));
end

RM5 (:,1) = extractfield(XDay_RM_Summary.G2_F62_42, 'Memory_Index');

% CCK37
T6(:,1) = (extractfield(XDay_RM_Summary.CCK_F6_37, 'Date1'))';
T6(:,2) = (extractfield(XDay_RM_Summary.CCK_F6_37, 'Date2'))';
T6 = datetime(T6,'InputFormat','yyyy-MM-dd');

for n = 1:size(T6,1)
    deltaT6(n,1) = daysact(T6(n,1),T6(n,2));
end

RM6 (:,1) = extractfield(XDay_RM_Summary.CCK_F6_37, 'Memory_Index');

% CaMK32
T7(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Date1'))';
T7(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Date2'))';
T7 = datetime(T7,'InputFormat','yyyy-MM-dd');

for n = 1:size(T7,1)
    deltaT7(n,1) = daysact(T7(n,1),T7(n,2));
end

RM7 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Memory_Index');

% Summarize the table and get ready for writing into Excel file
T_pWT = cat(1,deltaT1,deltaT2,deltaT3,deltaT4,deltaT5,deltaT6,deltaT7);
RM_pWT = cat(1,RM1,RM2,RM3,RM4,RM5,RM6,RM7);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% get cross-day RM vs deltaT for a5-i-KOs

% G17
T11(:,1) = (extractfield(XDay_RM_Summary.G2_F4_17, 'Date1'))';
T11(:,2) = (extractfield(XDay_RM_Summary.G2_F4_17, 'Date2'))';
T11 = datetime(T11,'InputFormat','yyyy-MM-dd');

for n = 1:size(T11,1)
    deltaT11(n,1) = daysact(T11(n,1),T11(n,2));
end

RM11 (:,1) = extractfield(XDay_RM_Summary.G2_F4_17, 'Memory_Index');

% G21
T22(:,1) = (extractfield(XDay_RM_Summary.G2_F52_21, 'Date1'))';
T22(:,2) = (extractfield(XDay_RM_Summary.G2_F52_21, 'Date2'))';
T22 = datetime(T22,'InputFormat','yyyy-MM-dd');

for n = 1:size(T22,1)
    deltaT22(n,1) = daysact(T22(n,1),T22(n,2));
end

RM22 (:,1) = extractfield(XDay_RM_Summary.G2_F52_21, 'Memory_Index');

% G45
T33(:,1) = (extractfield(XDay_RM_Summary.G2_F52_45, 'Date1'))';
T33(:,2) = (extractfield(XDay_RM_Summary.G2_F52_45, 'Date2'))';
T33 = datetime(T33,'InputFormat','yyyy-MM-dd');

for n = 1:size(T33,1)
    deltaT33(n,1) = daysact(T33(n,1),T33(n,2));
end

RM33 (:,1) = extractfield(XDay_RM_Summary.G2_F52_45, 'Memory_Index');

% G53
T44(:,1) = (extractfield(XDay_RM_Summary.G2_F52_53, 'Date1'))';
T44(:,2) = (extractfield(XDay_RM_Summary.G2_F52_53, 'Date2'))';
T44 = datetime(T44,'InputFormat','yyyy-MM-dd');

for n = 1:size(T44,1)
    deltaT44(n,1) = daysact(T44(n,1),T44(n,2));
end

RM44 (:,1) = extractfield(XDay_RM_Summary.G2_F52_53, 'Memory_Index');

% G36
T55(:,1) = (extractfield(XDay_RM_Summary.G2_F62_36, 'Date1'))';
T55(:,2) = (extractfield(XDay_RM_Summary.G2_F62_36, 'Date2'))';
T55 = datetime(T55,'InputFormat','yyyy-MM-dd');

for n = 1:size(T55,1)
    deltaT55(n,1) = daysact(T55(n,1),T55(n,2));
end

RM55 (:,1) = extractfield(XDay_RM_Summary.G2_F62_36, 'Memory_Index');

% Summarize the table and get ready for writing into Excel file
T_a5_i_KO = cat(1,deltaT11,deltaT22,deltaT33,deltaT44,deltaT55);
RM_a5_i_KO = cat(1,RM11,RM22,RM33,RM44,RM55);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% get cross-day RM vs deltaT for a5-pyr-KOs

% CaMK19
T111(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_19, 'Date1'))';
T111(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_19, 'Date2'))';
T111 = datetime(T111,'InputFormat','yyyy-MM-dd');

for n = 1:size(T111,1)
    deltaT111(n,1) = daysact(T111(n,1),T111(n,2));
end

RM111 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_19, 'Memory_Index');

% CaMK20
T222(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_20, 'Date1'))';
T222(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_20, 'Date2'))';
T222 = datetime(T222,'InputFormat','yyyy-MM-dd');

for n = 1:size(T222,1)
    deltaT222(n,1) = daysact(T222(n,1),T222(n,2));
end

RM222 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_20, 'Memory_Index');

% CaMK21
T333(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_21, 'Date1'))';
T333(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_21, 'Date2'))';
T333 = datetime(T333,'InputFormat','yyyy-MM-dd');

for n = 1:size(T333,1)
    deltaT333(n,1) = daysact(T333(n,1),T333(n,2));
end

RM333 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_21, 'Memory_Index');

% CaMK22
T444(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_22, 'Date1'))';
T444(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_22, 'Date2'))';
T444 = datetime(T444,'InputFormat','yyyy-MM-dd');

for n = 1:size(T444,1)
    deltaT444(n,1) = daysact(T444(n,1),T444(n,2));
end

RM444 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_22, 'Memory_Index');

% Summarize the table and get ready for writing into Excel file
T_a5_pyr_KO = cat(1,deltaT111,deltaT222,deltaT333,deltaT444);
RM_a5_pyr_KO = cat(1,RM111,RM222,RM333,RM444);


%% Get summary excel table
[ds, ~] = getdsap;

% for p-WT
p_WT = table(T_pWT, RM_pWT);
path = fullfile(ds.metadataPath, 'Prism excel data', 'p-WT_Xday_RM.xlsx');

if ~exist((fullfile(ds.metadataPath, 'Prism excel data')), 'dir')
    mkdir(fullfile(ds.metadataPath, 'Prism excel data'));
end
writetable(p_WT, path);

% for a5-i-KO
a5_i_KO = table(T_a5_i_KO,RM_a5_i_KO);
path = fullfile(ds.metadataPath, 'Prism excel data', 'a5-i-KO_Xday_RM.xlsx');

if ~exist((fullfile(ds.metadataPath, 'Prism excel data')), 'dir')
    mkdir(fullfile(ds.metadataPath, 'Prism excel data'));
end
writetable(a5_i_KO, path);

% for a5-pyr-KO
a5_pyr_KO = table(T_a5_pyr_KO, RM_a5_pyr_KO);
path = fullfile(ds.metadataPath, 'Prism excel data', 'a5-pyr-KO_Xday_RM.xlsx');

if ~exist((fullfile(ds.metadataPath, 'Prism excel data')), 'dir')
    mkdir(fullfile(ds.metadataPath, 'Prism excel data'));
end
writetable(a5_pyr_KO, path);

end